Quickstart Expo
This guide will help you to implement the Group Link Mobile SDK on your application written in React Native using the Expo framework on the managed workflow.
Step 1 - Installing the Group Link Expo Library
Inside the root of your expo managed project, you need to install some libraries to set up the necessary environment, there are some essential libraries you will need to install as shown below.
- expo-notifications
- expo-constants
- grouplink-sdk-expo-plugin
npx expo install expo-notifications &&
npx expo install expo-constants &&
npm install @grouplinknetwork/grouplink-sdk-expo-plugin
Step 2 - Plugin Configuration
After you installed all the necessary libraries, you will need to set up the Group Link plugin, to do this you have to insert the rn-grouplinksdk-expo-plugin with the necessary options, like the token to initialize the plugin, you need to insert this inside the plugins array on your app.json, you can find this file at the root folder.
"plugins": [
[
"@grouplinknetwork/grouplink-sdk-expo-plugin",
{
"token": "GROUP_LINK_TOKEN"
}
]
]
After this you'll need to run:
npx expo prebuild
cd ios && pod install
Here are all the params you can call within our plugin:
- token - string - The Group Link Initialization token
iOS Specific Configs - You need to call the bluetooth and location permission
If the Expo version is 52 or lower, it will be necessary to install a library for iOS:
npm install @grouplinknetwork/rn-grouplink-sdk
import * as GroupLinkSDK from '@grouplinknetwork/rn-grouplink-sdk';
export default function App() {
useEffect(()=>{
// This function requires the Group Link Token of your organization.
GroupLinkSDK.startGrouplinkIOS("GROUP_LINK_TOKEN");
GroupLinkSDK.startBluetoothIOS();
GroupLinkSDK.startLocationIOS();
},[])
return (
<View style={styles.container}>
<Text>Thats a test app</Text>
</View>
);
}
Info.plist strings - THESE STRINGS WILL NOT OVERRIDE ALREADY SETTED STRINGS
- NSLocationAlwaysAndWhenInUseUsageDescription - string - The ios Core Location Always usage string inside info.plist - default is "We need location permission for a better user experience."
- NSLocationWhenInUseUsageDescription - string - The ios Core Location While in Use string inside info.plist - default is "We need location permission to provide a better user experience."
- NSBluetoothPeripheralUsageDescription - string - The ios Core Bluetooth Peripheral usage string inside info.plist - default is "We need Bluetooth permission to provide a better user experience."
- NSBluetoothAlwaysUsageDescription - string - The ios Core Bluetooth Usage string inside info.plist - default is "We need Bluetooth permission to provide a better user experience."
Step 3 - Push Notifications Token Setup
To pass get your notification token, you will need to use the expo-notifications and expo-constants libraries, you can get the token string using the function below and send to our SDK via setDevicePushTokenIOS from our React Native SDK.
First, import the necessary depencencies to your application init file.
import Constants from "expo-constants";
import * as GroupLinkSDK from "@grouplinknetwork/rn-grouplink-sdk";
import * as Notifications from "expo-notifications";
After that, insert the parse notification function below
const getPushToken = () => {
if (!Constants.isDevice) {
return Promise.reject("YOU ARE RUNNING ON SIMULATOR");
}
try {
return Notifications.getPermissionsAsync()
.then((statusResult) => {
return statusResult.status !== "granted"
? Notifications.requestPermissionsAsync()
: statusResult;
})
.then((statusResult) => {
if (statusResult.status !== "granted") {
throw "Failed to get push token for push notification!";
}
return Notifications.getDevicePushTokenAsync();
})
.then((tokenData) => tokenData.data);
} catch (error) {
return Promise.reject("Couldn't check notifications permissions");
}
};
You can get the notification token using this function inside your code, we recommend using a useEffect with the application initialization to set the token inside our SDK, don't forget to import the React.
React.useEffect(() => {
getPushToken().then((token) => {
GroupLinkSDK.setDevicePushTokenIOS(token);
});
}, []);